package cn.edu.zjut.mina.bean;

import java.util.Arrays;

/**
 * 玩家类
 */
class Player {
	private Card[] cards;//玩家牌信息
	private int bet = 1;//下注(我理解为底分)   现在由于底分为1，所以暂时没有用
	private int mCredits = 0;//积分
	private boolean isBanker;//是否是庄家
	private int mBetRatio;//压注倍率   1，2，3
	private boolean hasNiuNiu = false;//是否有牛
	private int[] mNiuNiuPosition;//牛牛所在的位置
	private double coins;//玩家现有金币数 (暂时没用)
	private int maxCardsNum;//最大的牌的大小
	private int maxCardsColor;//最大牌的花色   0 方块      1 草花      2  红桃    3黑桃
	private int residueSum = 0;//剩余数和
	private boolean fiveTen = false;//是否拥有5张10
	private int mWinRatio;//赢得的倍率
	private int mCountOfNiuNiu = 0;//玩家一次对局中出现牛牛的次数
	private int mCountOfYouNiu = 0;//玩家一次对局中出现有牛的次数
	private int mCountOfWuHua = 0;//玩家一次对局中出现五花的次数
	private boolean mLastRoundPoNiu = false;//玩家上一局是否破牛  (在破牛庄的时候有用)   ture 表示破牛了              false表示没有破牛
	
	public Player() {
		mNiuNiuPosition = new int[3];
		hasNiuNiu = false;
	}
	
	public Card[] getCards() {
		return cards;
	}
	
	public void setCards(Card[] cards) {
		this.cards = cards;
	}
	
	public int getBet() {
		return bet;
	}
	
	public void setBet(int bet) {
		this.bet = bet;
	}
	
	public int getmCredits() {
		return mCredits;
	}

	public void setmCredits(int mCredits) {
		this.mCredits = mCredits;
	}
	
	public boolean isBanker() {
		return isBanker;
	}
	
	public void setBanker(boolean isBanker) {
		this.isBanker = isBanker;
	}
	
	public int getmBetRatio() {
		return mBetRatio;
	}
	
	public void setmBetRatio(int mBetRatio) {
		this.mBetRatio = mBetRatio;
	}
	
	public boolean isHasNiuNiu() {
		return hasNiuNiu;
	}
	
	public void setHasNiuNiu(boolean hasNiuNiu) {
		this.hasNiuNiu = hasNiuNiu;
	}
	
	public int[] getmNiuNiuPosition() {
		return mNiuNiuPosition;
	}
	
	public void setmNiuNiuPosition(int[] mNiuNiuPosition) {
		this.mNiuNiuPosition = mNiuNiuPosition;
	}
	
	public double getCoins() {
		return coins;
	}
	
	public void setCoins(double coins) {
		this.coins = coins;
	}
	
	public int getMaxCardsNum() {
		return maxCardsNum;
	}
	
	public void setMaxCardsNum(int maxCardsNum) {
		this.maxCardsNum = maxCardsNum;
	}
	
	public int getMaxCardsColor() {
		return maxCardsColor;
	}
	
	public void setMaxCardsColor(int maxCardsColor) {
		this.maxCardsColor = maxCardsColor;
	}
	
	public int getResidueSum() {
		return residueSum;
	}
	
	public void setResidueSum(int residueSum) {
		this.residueSum = residueSum;
	}
	
	public boolean isFiveTen() {
		return fiveTen;
	}
	
	public void setFiveTen(boolean fiveTen) {
		this.fiveTen = fiveTen;
	}
	
	public int getmWinRatio() {
		return mWinRatio;
	}

	public void setmWinRatio(int mWinRatio) {
		this.mWinRatio = mWinRatio;
	}
	
	public int getmCountOfNiuNiu() {
		return mCountOfNiuNiu;
	}

	public void setmCountOfNiuNiu(int mCountOfNiuNiu) {
		this.mCountOfNiuNiu = mCountOfNiuNiu;
	}
	
	public int getmCountOfYouNiu() {
		return mCountOfYouNiu;
	}

	public void setmCountOfYouNiu(int mCountOfYouNiu) {
		this.mCountOfYouNiu = mCountOfYouNiu;
	}

	public int getmCountOfWuHua() {
		return mCountOfWuHua;
	}

	public void setmCountOfWuHua(int mCountOfWuHua) {
		this.mCountOfWuHua = mCountOfWuHua;
	}
	
	public boolean ismLastRoundPoNiu() {
		return mLastRoundPoNiu;
	}

	public void setmLastRoundPoNiu(boolean mLastRoundPoNiu) {
		this.mLastRoundPoNiu = mLastRoundPoNiu;
	}
	
	public void getConcreteCards() {
		for(int i = 0; i < cards.length; i++) {
			if (cards[i].getColor() == 0) {
				System.out.print("方块" + cards[i].getNumber() + " ");
			} else if (cards[i].getColor() == 1) {
				System.out.print("草花" + cards[i].getNumber() + " ");
			} else if (cards[i].getColor() == 2) {
				System.out.print("红桃" + cards[i].getNumber() + " ");
			} else if (cards[i].getColor() == 3) {
				System.out.print("黑桃" + cards[i].getNumber() + " ");
			}
		}
		System.out.println();//换行
	}
	
	public void computeNiuNiu() {
		/**
		 * 计算是否有牛牛与牛牛的位置
		 */
		for (int i = 0; i < 3; i++) {
			if (hasNiuNiu == true)
				break;
			for (int j = i + 1; j < 4; j++) {
				if (hasNiuNiu == true)
					break;
				for (int k = j + 1; k < 5; k++) {
					if (hasNiuNiu == true)
						break;
					int digit1 = cards[i].getNumber() > 10?10:cards[i].getNumber();//J,Q,K都是当10计算
					int digit2 = cards[j].getNumber() > 10?10:cards[j].getNumber();
					int digit3 = cards[k].getNumber() > 10?10:cards[k].getNumber();
					int sum = digit1 + digit2 + digit3;
					if (sum % 10 == 0) {
						mNiuNiuPosition[0] = i;
						mNiuNiuPosition[1] = j;
						mNiuNiuPosition[2] = k;
						hasNiuNiu = true;
					}
				}
			}
		}
		/**
		 * 在有牛的情况下，判断是不是有5个10
		 */
		if (hasNiuNiu == true) {
			System.out.println("有牛");
			System.out.println("下标位置    " + mNiuNiuPosition[0] + " " + mNiuNiuPosition[1] + " " + mNiuNiuPosition[2]);
			mCountOfYouNiu ++;//有牛次数加一
			int tempFiveTen = 0;//0 表示5个10   1表示存在至少一张牌点数小于10
			for (int i = 0; i < PlayingCards.NUMBER_OF_CARDS; i++) {
				if (cards[i].getNumber() < 10) {
					tempFiveTen = 1;
					break;
				}	
			}
			
			if (tempFiveTen == 0) {
				setFiveTen(true);
				mCountOfWuHua ++;//五花次数加一
			}
		}
		
		/**
		 * 拷贝牌的副本用于排序
		 * 不管有没有牛都要获取最大牌
		 */
		Card[] tempCards = new Card[5];
		for (int i = 0; i < PlayingCards.NUMBER_OF_CARDS; i++) {
			tempCards[i] = cards[i];
		}
		Arrays.sort(tempCards);//排序
//		for(int i = 0; i < tempCards.length; i++) {
//			System.out.print(tempCards[i].getColor() + " " + tempCards[i].getNumber() + " ");
//		}
//		System.out.println();
		setMaxCardsNum(tempCards[0].getNumber());//获取最大牌的点数
		setMaxCardsColor(tempCards[0].getColor());//获取最大牌的颜色
//		System.out.println(maxCardsNum + " " + maxCardsColor);
		tempCards = null;//释放资源
	}
	
	public void computeResidueSum () {//计算剩余和
		for (int i = 0; i < PlayingCards.NUMBER_OF_CARDS; i++) {
			if (i != mNiuNiuPosition[0] && i != mNiuNiuPosition[1] && i != mNiuNiuPosition[2]) {
				residueSum += cards[i].getNumber() > 10?10:cards[i].getNumber();
			}
		}
		if (!fiveTen && residueSum % 10 == 0) {
			mCountOfNiuNiu ++;//牛牛次数加一
		}
		System.out.println("residueSum(也就是M) " + residueSum);
	}
	
	public void reSet () {//重置其中一些变量
		cards = null;
		isBanker = false;//是否是庄家
		mBetRatio = 1;//压注倍率
		hasNiuNiu = false;//是否有牛
		maxCardsNum = 0;//最大的牌的大小
		maxCardsColor = 0;//最大牌的花色   0 方块      1 草花      2  红桃    3黑桃
		residueSum = 0;//剩余数和
		fiveTen = false;//是否拥有5张10
		mWinRatio = 0;//赢得的倍率
	}
}
